<?php
if (!defined('APP') or !constant('APP')) die('Direct access not allowed!');
ini_set('display_errors', 1); 
ini_set('log_errors', 1); 

class UserRankModel {
    
    public static function exist($id_demot)
    {
        $query = "SELECT id FROM `users_ranks` WHERE id_demot = :id_demot AND id_user = :id_user;";
        $result = DB::getPDO()->prepare($query);
        $result->execute(array(
            ':id_demot' => intval($id_demot),
            ':id_user'  => intval(UserModel::isLoggedIn()) 
            ));  
        $result = $result->fetchAll();
                
        if (sizeof($result) < 1) { return false; }
        
        return true;   
    }
    
    public static function save($id_demot)
    {
        
        $id_demot = isset($id_demot) ? intval($id_demot) : 0;
        
        $data=array(
            ':id_demot'=> $id_demot,
            ':id_user' => intval(UserModel::isLoggedIn()) );
       
        $query = "INSERT INTO `users_ranks` (`id_user`, `id_demot`) VALUES (:id_user, :id_demot);";
        
        $result = DB::getPDO()->prepare($query);
        return $result->execute($data);      
    }

}